//
//  BaseViewController.m
//  TangYi
//
//  Created by dllo on 15/10/27.
//  Copyright (c) 2015年 赵连鹏. All rights reserved.
//

#import "BaseViewController.h"
#import <AFNetworking.h>
#import <MBProgressHUD.h>

@interface BaseViewController ()

@property(nonatomic, retain) MBProgressHUD *hud;


@end

@implementation BaseViewController

- (void)dealloc {
    [_hud release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationController.navigationBar.translucent = NO;
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], NSForegroundColorAttributeName, nil]];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.893 green:0.451 blue:0.472 alpha:1.000];

//    // 接收网络状态通知
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkStatus:) name:@"NotificationNetStatus" object:[[UIApplication sharedApplication] delegate]];
    
    
//    [self isWlan];

    
}

#pragma mark - Notification & KVO

- (void)networkStatus:(NSNotification *)notifi
{
    
    
    switch ([notifi.userInfo[@"netStatus"] integerValue]) {
        case AFNetworkReachabilityStatusNotReachable:
            
            NSLog(@"没有网络");
            [self createNetStatusAlert:@"没有接入网络"];
            break;
            
        case AFNetworkReachabilityStatusUnknown:
            
            NSLog(@"未知网络");
            [self createNetStatusAlert:@"未知网络"];
            break;
            
        case AFNetworkReachabilityStatusReachableViaWiFi:
            
            NSLog(@"WiFi");
            [self createNetStatusAlert:@"使用wifi网络"];
            break;
            
        case AFNetworkReachabilityStatusReachableViaWWAN:
            
            NSLog(@"手机网络");
            [self createNetStatusAlert:@"使用3G/4G网络"];
            break;
            
        default:
            break;
    }
}



- (void)createNetStatusAlert:(NSString *)labelText
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.labelText = labelText;
    
    hud.removeFromSuperViewOnHide = YES;
    
    hud.yOffset = (HEIGHT - 64 - 49) / 2 - 50;
    
    hud.labelFont = [UIFont systemFontOfSize:15];
    
    [hud hide:YES afterDelay:2];
}

//- (void)isWlan {
//    
//    AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
//    [manager startMonitoring];
//    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
//        
//        if (status == 2 || status == 1) {
//            
//            self.isNetwork = YES;
//         
//            
//        } else if (status == 0) {
//            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"没有网络" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
//            [alert show];
//            
//            self.isNetwork = NO;
//            
//        } else {
//            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"未知的网络" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
//            [alert show];
//            
//            self.isNetwork = NO;
//        }
//        
//    }];
//    
//}

- (void)viewWillAppear:(BOOL)animated {
    self.tabBarController.tabBar.hidden = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
